<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>类的基本知识</title>
</head>
<body>
    <script type="text/javascript">
        //创建一个person类
        class Person{
            constructor(name,age){
                this.name = name;
                this.age = age;
            }
            //通过Person实例调用speak时,speak中的this就是person实例
            speak(){
                console.log(`${this.name}今年${this.age}岁`);
            }
        }

        class Student extends Person{
            constructor(name,age,school){
                //super()调用父类的构造函数，必须写在子类构造函数的第一行
                super(name,age);
                this.school = school;
            }
            study(){
                console.log(`${this.name}正在学习`);
            }
            speak(){
                //super.speak()调用父类的speak方法
                super.speak();
                console.log(`${this.name}来自${this.school}`);
            }
        }

        //创建一个对象
        let s1 = new Student('小明',18,'清华大学');
        let s2 = new Student('小红',19,'北京大学');

        console.log(s1);
        console.log(s2);
        s1.speak();
    </script>

</body>
</html>